<template>
  <div class="deawer">
    <div class="detailBox" style="height:100px">
      <v-tableTitle :btnConfig="btnConfig" :tableSelectData="selectData" @cancel="cancel" @save="save"></v-tableTitle>
      <el-form ref="form" label-width="80px" inline>
        <el-form-item :label="this.$t('config.areaName')" required>
          <el-input v-model="areakey" :disabled="!!$route.query?.areakey"></el-input>
        </el-form-item>
      </el-form>
      
    </div>
    <div class="detailListBox">
      <!-- <v-tableTitle :btnConfig="btnConfig1" :tableSelectData="selectData" @cancel="cancel" @save="save" @del="del"></v-tableTitle> -->
      <v-detailList :areakey="areakey" ref="detailList"></v-detailList>
    </div>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import tableTitle from "commons/TableTitle";
import detailList from "../detailsList/DetailList"

export default {
  name: "",
  mixins: [baseMixin],
  data() {
    return {
      selectData: [],
      areakey:""
    };
  },
  computed: {
    btnConfig(){
      return [
        { label: this.$t('common.save'), certigier: !this.btnPermNameList.includes('WM03100103'), invalid: "save" },
        { label: this.$t('common.cancel'), certigier: !this.btnPermNameList.includes('WM03100104'), invalid: "cancel" },
      ]
    },
  },
  created() {
  },
  methods: {
    //保存按钮
    async save() {
      if(!this.areakey){
        return this.$message.error(this.$tj('config.areaName','app.emptyMes'))
      }
      let flag = this.$refs.detailList.$children[1].$refs.input.submitForm("from");
      if (!flag) {
        return;
      }
      let datailsListData = this.$refs.detailList.detailData;
      datailsListData.areakey = this.areakey;
      try {
        let res = await this.$api.post('/insertArea', datailsListData);
        
          this.$message.success(res.returnMgr);
          this.cancel()
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //弹框取消
    cancel() {
      this.$router.push({ name: "area" });
    },
  },
  mounted(){
    this.areakey = this.$route.query?.areakey;
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-detailList": detailList,
  }
}
</script>

<style scoped>

</style>
